package cn.hrlly.tao2shou.presenter;

import android.content.Context;

import cn.hrlly.tao2shou.biz.FindPasswordBiz;
import cn.hrlly.tao2shou.biz.FindPasswordBizImpl;
import cn.hrlly.tao2shou.domain.User;
import cn.hrlly.tao2shou.listener.OnFindPasswordListener;
import cn.hrlly.tao2shou.view.view_interface.FindPasswordView;

/**
 * User: gengliang
 * Date: 2016-01-27
 * Time: 11:04
 */

public class FindPasswordPresenterImpl implements OnFindPasswordListener,FindPasswordPresenter {

    private FindPasswordBiz findPasswordBiz;
    private FindPasswordView findPasswordView;

    public FindPasswordPresenterImpl(FindPasswordView findPasswordView,Context context){
        this.findPasswordBiz=new FindPasswordBizImpl(this,context);
        this.findPasswordView=findPasswordView;
    }

    @Override
    public void getCode() {
        User user=new User();
        user.setPhoneNumber(findPasswordView.getPhoneNumber());
        findPasswordBiz.getVerificationCode(user);
    }

    @Override
    public void findPassword() {
        User user=new User();
        user.setPhoneNumber(findPasswordView.getPhoneNumber());
        user.setPassword(findPasswordView.getNewPassword());
        user.setVerificationCode(findPasswordView.getVerificationCode());
        user.setLongditude(findPasswordView.getLongitude());
        user.setLantitude(findPasswordView.getLantitude());
        findPasswordBiz.findPassword(user);
    }

    @Override
    public void closeDataBase() {
        findPasswordBiz.closeDataBase();
    }

    @Override
    public void getVerificationFail(String errorMessage) {
        findPasswordView.showMessage(errorMessage);
    }

    @Override
    public void getVerificationFail(int errorMessage) {
        findPasswordView.showMessage(errorMessage);
    }

    @Override
    public void findPasswordSucc(final User user) {
        findPasswordView.startActivity();

        //将用户信息存在数据库中，在io线程操作
        findPasswordBiz.saveUserInfo(user);
    }

    @Override
    public void findPasswordFail(String errorMessage) {
        findPasswordView.showMessage(errorMessage);
    }

    @Override
    public void findPasswordFail(int errorMessage) {
        findPasswordView.showMessage(errorMessage);
    }
}
